//
//  HeaderView.m
//  dhfsAPP
//
//  Created by Devil on 2017/7/31.
//  Copyright © 2017年 Devil. All rights reserved.
//


#import "HeaderView.h"

@implementation HeaderView

#pragma mark - 懒加载
-(UIButton *)backButton{
    if (!_backButton) {
        _backButton = [UIButton buttonWithType:UIButtonTypeCustom];
        
        _backButton.frame = CGRectMake(0, 0, WIDTH(96), HEIGHT(128));
        
        UIImageView *imgV = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"return"]];
        
        imgV.frame = CGRectMake(WIDTH(23), HEIGHT(62), WIDTH(25), HEIGHT(45));
        
        [_backButton addSubview:imgV];
        
        [_backButton addTarget:self action:@selector(click) forControlEvents:UIControlEventTouchUpInside];
    }
    
    return _backButton;
}

-(UILabel *)title:(NSString *)title{
    if (!_title) {
        _title = [[UILabel alloc] initWithFrame:CGRectMake(0, HEIGHT(55), 0, 0)];
        
        _title.text = title;
        
        _title.textColor = [UIColor whiteColor];
        
        _title.font = [UIFont fontWithName:@"PingFangSC-Regular" size:HEIGHT(42)];
        
        [_title sizeToFit];
        
        _title.center = CGPointMake(self.center.x, _title.center.y);

    }
    
    return _title;
}

#pragma mark - 构造函数
-(instancetype)initWithFrame:(CGRect)frame Title:(NSString *)title{
    self = [super initWithFrame:frame];
    
    if (self) {
        self.backgroundColor = RGB(0, 105, 193);
        
        [self initUIWithTitle:title];
    }
    
    return self;
}

#pragma mark - 其它函数
-(void)initUIWithTitle:(NSString *)title{
    [self addSubview:self.backButton];
    
    self.title = [self title:title];
    [self addSubview:self.title];
}

-(void)click{
    if ([self.headerViewDelegate respondsToSelector:@selector(clickHeaderViewBtn)]) {
        [self.headerViewDelegate clickHeaderViewBtn];
    }
}
@end
